/**
 * 
 */
package com.mdxl.first.Dao.db;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.code.morphia.Datastore;
import com.google.code.morphia.Morphia;
import com.mongodb.DB;
import com.mongodb.MongoClient;

/**
 * 数据库连接抽象类
 *
 */
public abstract class AbstarctMongoDBConnection {

	protected static Logger logger = LoggerFactory.getLogger(AbstarctMongoDBConnection.class);

	protected MongoClient instance = null;

	protected boolean isRenew = false;
	
	protected volatile boolean isShard = true;
	/**
	 * 子类实现连接数据库
	 * @return
	 */
	public abstract MongoClient getMongoClient();

	@SuppressWarnings("deprecation")
	public DB getDB(String dbname) {
		return getMongoClient().getDB(dbname);
	}

	public Datastore getDataStore(String dbname) {
		Morphia morphia = new Morphia();
		return morphia.createDatastore(getMongoClient(), dbname);
	}

	public boolean isShard() {
		return isShard;
	}

}
